<template>
	<z-paging ref="paging" v-model="dataList" @query="queryList"
		:loading-more-custom-style="{ paddingBottom: 'env(safe-area-inset-bottom)' }">
		<template #top>
			<view class="zpagin_top">
				<nav-bar :iconLeft="true" />
				<view class="search">
					<custom-search v-model="queryParams.search" @search="refreshList" placeholder="请输入标题" />
				</view>
				<dui-float-ball :pathUrl="`${pageUrl}/compile`" v-if="$hasPerm(['30401'])" />
			</view>
		</template>
		<u-swipe-action>
			<u-swipe-action-item v-for="item in dataList" :key="item.id"
				:name="JSON.stringify(swipeActPer(options, item.dispose_status)) + '&' + item.id + '&' + item.name"
				:options="swipeActPer(options, item.dispose_status)"
				:disabled="swipeActPer(options, item.dispose_status, 'disabled')" @click="action">
				<uni-card margin="0" spacing="0">
					<template v-slot:title>
						<uni-list>
							<uni-list-item :title="item.client_name" :note="item.code" thumbSize="lg">
								<template v-slot:footer>
									<up-tag size="mini" :text="status_list[item.dispose_status].text" plain plainFill
										:type="status_list[item.dispose_status].type" />
								</template>
							</uni-list-item>
						</uni-list>
					</template>
					<view>标题：{{ item.title }}</view>
					<view class="con" style="align-items: normal;">
						<view class="ctent" style="flex: none;">内容：</view>
						<view class="ctent">{{ item.content }}</view>
					</view>
					<view>执行日期：{{ item.use_date }}</view>
					<view class="con" style="align-items: normal;">
						<view class="ctent" style="flex: none;">处理结果：</view>
						<view class="ctent">{{ item.dispose_res }}</view>
					</view>
					<view>处理人：{{ item.use_full_name }}</view>
					<view>处理时间：{{ item.dispose_date }}</view>
					<view>登记人：{{ item.create_full_name }}</view>
					<view>登记日期：{{ item.create_date }}</view>
					<view class="con_button" v-if="$hasPerm(['30405'])" v-show="item.dispose_status == 0"
						@click.stop="hanldAct(item.id)"> 处理
					</view>
				</uni-card>

			</u-swipe-action-item>
		</u-swipe-action>
	</z-paging>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import clMemoApi from '../../../api/clientt/cl_memo'
import { swipeActPer } from '@/utils/permission' // 用防抖优化请求频率（下面给出）

uni.$bus.useBusOn('cl_memo:refresh', refreshList)

;
const status_list = {
	0: {
		text: '未处理',
		type: 'error'
	},
	1: {
		text: '已处理',
		type: 'success'
	},
};

const options = [
	{
		text: '修改',
		per: '30402',
		style: {
			backgroundColor: '#0081ff'
		}
	}, {
		text: '删除',
		per: '30403',
		style: {
			backgroundColor: '#f56c6c'
		}
	}
];

const pageUrl = '/views/clientt/cl_memo';
const queryParams = reactive({
	search: '',
});
const paging = ref(null)
const dataList = ref([]);

function queryList(pageNo, pageSize) {
	const params = {
		page: pageNo,
		page_size: pageSize,
		...queryParams
	}
	clMemoApi.get_client_memo(params).then((res) => {
		paging.value.complete(res.results);
	})
};

function hanldAct(id) {
	uni.navigateTo({
		url: `${pageUrl}/compile?type=dispose&id=${id}`
	})
};


//滑动操作按钮
function action(v) {
	const options = JSON.parse(v.name.split("&")[0])
	const id = v.name.split("&")[1]
	const delName = v.name.split("&")[2]
	const index = v.index
	if (options[index].text == '修改') {
		uni.navigateTo({
			url: `${pageUrl}/compile?type=edit&id=${id}`
		})
	}
	if (options[index].text == '删除') {
		delete_type(id, delName)
	}
};
//删除操作
function delete_type(id, delName) {
	uni.showModal({
		title: '提示',
		content: `确认要删除吗？`,
		success: (res) => {
			if (res.confirm) {
				clMemoApi.delete_client_memo(id).then((res) => {
					uni.$u.toast('删除成功')
					setTimeout(() => {
						refreshList()
					}, 500)
				})
			}
		}
	});
};

//编辑跳转刷新
function refreshList() {
	paging.value.reload();
}
</script>

<style lang="scss"></style>